cmake_minimum_required(VERSION 3.10)

project(OpenGLExample)

#${CMAKE_SOURCE_DIR} 这个是cmakelists所在的位置
# runtime输出目录是生成二进制的目录

# 指定生成目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)

include_directories(${CMAKE_SOURCE_DIR}/include)

find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)

include_directories(/usr/include)
find_library(GLFW_LIBRARY NAMES glfw HINTS "/usr/lib" "/usr/lib64")

if(NOT GLFW_LIBRARY)
    message(FATAL_ERROR "GLFW library not found")
else()
    message(STATUS "Found GLFW: ${GLFW_LIBRARY}")
endif()

set(DRAWER_SRC
    src/drawer/drawer.cpp
    src/drawer/screen.cpp
    src/drawer/raster.cpp
)

set(MAIN_SRC
    src/main/main.cpp
)

set(TEST1_SRC
    src/main/test1.cpp
)

set(TESTDLL_SRC
    src/main/testDll.cpp
)

set(DLL_SRC
    src/main/dll.cpp
)

set(HANDLER_SRC
    src/handler/handler.cpp
)

set(OBJECT_SRC
    src/object/world.cpp
    src/object/triangle.cpp
)

set(TRANSFORMATION_SRC
    src/transformation/viewPort.cpp
    src/transformation/move.cpp
    src/transformation/rotation.cpp
    src/transformation/scale.cpp
    src/transformation/project.cpp
    src/transformation/transformation.cpp
)

set(CAMERA_SRC
    src/camera/camera.cpp
)

set(REQUIRED_LIBS ${GLFW_LIBRARY} GLEW OpenGL::GL)

#设立一个包含所有源文件的变量，方便引用
set(ALL_SRC ${MAIN_SRC} ${TEST1_SRC} ${TRANSFORMATION_SRC} ${DRAWER_SRC} ${HANDLER_SRC} ${OBJECT_SRC} ${CAMERA_SRC})

#生成主程序可执行文件 OpenGLExample
add_executable(OpenGLExample ${MAIN_SRC} )
target_link_libraries(OpenGLExample ${REQUIRED_LIBS})

#生成测试程序可执行文件 TestProgram
add_executable(TestProgram ${TEST1_SRC} ${TRANSFORMATION_SRC} ${DRAWER_SRC} ${HANDLER_SRC} ${OBJECT_SRC} ${CAMERA_SRC})
target_link_libraries(TestProgram ${REQUIRED_LIBS})

#生成测试程序可执行文件 TestProgram
add_executable(TestDll ${TESTDLL_SRC} ${TRANSFORMATION_SRC} ${DRAWER_SRC} ${HANDLER_SRC} ${OBJECT_SRC} ${CAMERA_SRC} ${DLL_SRC})
target_link_libraries(TestDll ${REQUIRED_LIBS})

add_library(DLL SHARED ${DLL_SRC} ${TRANSFORMATION_SRC} ${DRAWER_SRC} ${HANDLER_SRC} ${OBJECT_SRC} ${CAMERA_SRC})
target_include_directories(DLL PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(DLL PRIVATE ${REQUIRED_LIBS})